/**
 * Created by Administrator on 2017/8/20.
 */
var website = {
    form: null,
    url: null,
    title: null,
    desc: null,

    init: function () {
        website.initBind();
        website.initEvent();
    },

    initBind: function () {
        website.form = $("form");
        website.url = $('#website-url');
        website.title = $('#website-title');
        website.desc = $('#website-desc');
    },

    initEvent: function () {
        website.url.change(function () {
            var url = $('#website-url').val();
            var reg = new RegExp('[a-zA-z]+://[^\\s]*');
            if (url.match(reg)) {
                $.ajax({

                    url: '/website/get-website-info',
                    type: 'post',
                    dataType: 'json',
                    data: {'url': url},
                    success: function (data) {
                        console.log(data);
                        website.title.val(data.title);
                        website.desc.val(data.desc);
                    },
                    error: function () {
                        website.title.val('');
                        website.desc.val('');
                    },
                });
            } else {

                website.title.val('');
                website.desc.val('');
            }
        });
    },

};
$(function () {
    website.init();
});